package com.ziyucoding.springboot.labs.lab4.concurrentdemo.example.publish;

import com.ziyucoding.springboot.labs.lab4.concurrentdemo.annoations.NotThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

/**
 * 不安全的发布
 *
 * @author ziyucoding
 * @date 2022-11-27
 **/
@Slf4j
@NotThreadSafe
public class UnsafePublishDemo1 {

    /**
     * 公司名称
     */
    private String[] companyNames = {"Apple", "Google"};

    public String[] getCompanyNames() {
        return companyNames;
    }

    public static void main(String[] args) {
        UnsafePublishDemo1 item = new UnsafePublishDemo1();
        log.info("{}", Arrays.toString(item.getCompanyNames()));
        // [Apple, Google]

        // 修改私有属性
        item.companyNames[0] = "JD";
        log.info("{}", Arrays.toString(item.getCompanyNames()));
        // [JD, Google]
    }

}
